package cn.aixuegao.common.config;

import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

import cn.aixuegao.common.constant.BeanNames;

@Configuration
@EnableCaching
public class EhcacheConfig {

	 /** 
     * ehcache 主要的管理器 
     * @param bean 
     * @return 
     */  
    @Bean(name=BeanNames.EhCacheCacheManager_BEAN_NAME)  
    public EhCacheCacheManager ehCacheCacheManager(EhCacheManagerFactoryBean bean){  
    	return new EhCacheCacheManager(bean.getObject());  
    }  
    @Bean  
    public EhCacheManagerFactoryBean ehCacheManagerFactoryBean(){  
        EhCacheManagerFactoryBean factoryBean = new EhCacheManagerFactoryBean();  
        factoryBean.setConfigLocation(new ClassPathResource("ehcache.xml"));  
        factoryBean.setShared(true);  
        return factoryBean;  
    } 
}
